<!--
- Author:   .
- Date:    2017/7/4 0004.
- File:    my.
-->
<template>
  <div>
    <div class="Web_Box">
      <!--<div class="Confirmationhints" v-show="memberInfo.is_brush_man == '1'">-->
        <!--<ul class="f-cb">-->
          <!--<li :class="{'on': !needGoods}" @click="switchNeedGoods(false)">-->
            <!--<i class="iconfont icon-xuanze"></i>-->
            <!--<h4>无需寄货</h4>-->
            <!--<p>购买后商家不发货，可返现</p></li>-->
          <!--<li :class="{'on': needGoods}" @click="switchNeedGoods(true)">-->
            <!--<i class="iconfont icon-xuanze"></i>-->
            <!--<h4>需要寄货</h4>-->
            <!--<p>购买后商家发货，不可返现</p>-->
          <!--</li>-->
        <!--</ul>-->
      <!--</div>-->
      <div style="padding-bottom: 200px;" class="ConfirmationOrder">
        <div class="ConsigneeInfo" v-show="type == 0">
          <div class="add_adree" v-show="addressList.requested && addressList.data.length <= 0" @click="gotoAddAddress">添加收货地址</div>
          <div v-show="addressList.requested && addressList.data.length > 0" @click="selectAddress">
            <p class="text1 f-cb"><span class="name fl">收货人:{{address.true_name}} </span>
              <span class="tel fr">{{address.mob_phone}}</span></p>
            <div class="Address slh2">{{address.area_info}} <span v-show="needGoods">{{address.address}}</span><span v-show="!needGoods">到货后请电话联系</span>
            </div>
            <i class="iconfont icon-rightdot"></i></div>
        </div>
        <div class="ConsigneeInfo" style="background: #fff; margin-bottom: 0.25rem" v-show="type == 1">
          <div class="add_adree" v-show="shopAddressList.requested && shopAddressList.data.length <= 0">当前无线下商店数据，暂不能自提</div>
          <div v-show="shopAddressList.requested && shopAddressList.data.length > 0" @click="selectShopAddress">
            <p class="text1 f-cb">
              <span class="name fl"><span class="cr_f23030 pr5">自提门店</span> {{shopAddress.seller_name}} </span>
              <span class="tel fr">{{shopAddress.telphone}}</span></p>
            <div class="Address slh2">{{shopAddress.area_info}} {{shopAddress.address}}</div>
            <i class="iconfont icon-rightdot"></i></div>
        </div>
        <div class="ShopGoods EditPro hidden bor_b_dcdddd">
          <div class="order_ts" v-show="memberInfo.is_brush_man == '1' && !needGoods">此订单可获得{{integralGet | toFixed(2)}}积分</div>
          <div class="ProList">
            <!--<div class="oeder_tex">订单号:2362356239521521</div>-->
            <ul>
              <li v-for="item in buyInfo.alldata">
                <div class="Pic"><img :src="hostName + $config.goodsImgSrc + item.goods_image" alt=""/></div>
                <div class="Con">
                  <div class="pl20">
                    <h2 class="">{{item.goods_name}}&nbsp;&nbsp;<span v-for="attr in item.goods_spec">{{attr.name}} </span>
                    </h2>
                    <!--<p class="Attribute"><span v-for="attr in item.goods_spec">{{attr.name}} </span></p>-->
                    <p class="PriceQuantity" v-if="buyInfo.gc_id == 4">
                      <span class="fl cr_f84e37">{{item.goods_price | discount(item.groupbuy_rebate)}}</span><span class="fr cr_282828">×{{item.goods_num}}</span>
                    </p>
                    <p class="PriceQuantity" v-else>
                      <span class="fl cr_f84e37">￥{{item.goods_price | discount(item.groupbuy_rebate)}}</span><span class="fr cr_282828">×{{item.goods_num}}</span>
                    </p>
                  </div>
                </div>
              </li>
              <li>
                <p style="font-size: 14px" v-if="buyInfo.gc_id == 4">合计:<span class="cr_f84e37">{{buyInfo.total}} &nbsp;</span>
                </p>
                <p style="font-size: 14px" v-else>合计:<span class="cr_f84e37">￥{{buyInfo.total}} &nbsp;</span>
              </p></li>
            </ul>
          </div>
        </div>
        <div class="OtherInfo">
          <ul>
            <li v-show="false"><!--已不用此功能-->
              <div class="tit">可使用余额支付 </div>
              <div class=" pr50">
                <span class="cr_fd6847 ml10">￥{{balanceUsed | toFixed(2)}}</span>

              </div>
              <i v-show="!useBalance" class="iconfont icon-pitch2" @click="switchUseBalance(true)"></i>
              <i v-show="useBalance" class="iconfont icon-select" @click="switchUseBalance(false)"></i></li>
            <li style="height:55px; line-height:40px;" v-show="false"><!--已不用此功能-->
              <div class="tit">可使用积分抵扣</div>
              <div class=" pr50">
                <span class="cr_fd6847 ml10">￥{{integralUsed | toFixed(2)}}</span>
                <!--<span class="ml10">(总积分:{{buyInfo.integral}})</span>-->
                <p class=" f12 cr_898989 tis ">每次购买最多可使用订单商品总额50%的积分抵扣</p>
              </div>
              <i v-show="!useIntegral" class="iconfont icon-pitch2" @click="switchIntegral(true)"></i>
              <i v-show="useIntegral" class="iconfont icon-select" @click="switchIntegral(false)"></i>

            </li>

            <!--<li>-->
              <!--<div class="tit">配送方式</div>-->
              <!--<div class="fr pr20 f24 cr_000">包邮</div>-->
              <!--&lt;!&ndash;<i class="iconfont icon-rightdot2"></i></li>&ndash;&gt;-->
            <!--<li class="Total" style=" height:80px;"><textarea placeholder="买家留言" v-model="remark"></textarea></li>-->
          </ul>
        </div>
      </div>
    </div>
    <div class="EditReceiptAddress" style="position: fixed; left: 0; bottom: 60px; width: 100%; background:#fff; border-top:1px #ddd solid;z-index: 99">
      <ul v-if="buyInfo.gc_id == 4">
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
          <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
          <div class="fl lh100 f26 cr_595757 ml5" style=""> <span class="totals" style="">拥有云宝：</span><span class="cr_fd6847">{{memberInfo.freeze_balance}}</span>
          </div>
          <input type="number" v-model="hm_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用云宝数量"/>

          <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
          <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
          <div class="fl lh100 f26 cr_595757 ml5"> <span class="totals" style="">拥有云通证：</span><span class="cr_fd6847">{{memberInfo.hg_balance}}</span>
          </div>
          <input type="number" v-model="hg_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用云通证数量"/>
          <!--<div style="width: 55%;position: absolute;right: 0px" ><span>需支付：</span><span>{{payed * 0.2 | toFixed(2)}}花股</span></div>-->
          <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
          <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
          <div class="fl lh100 f26 cr_595757 ml5"> <span class="totals" style="">拥有云积分：</span><span class="cr_fd6847">{{memberInfo.hf_balance}}</span>
          </div>
          <input type="number" v-model="hf_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用云积分数量"/>
          <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
      </ul>
      <ul v-else-if="buyInfo.gc_id == 3">
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
        <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
        <div class="fl lh100 f26 cr_595757 ml5" style=""> <span class="totals" style="">拥有云劵：</span><span class="cr_fd6847">{{memberInfo.hq_balance}}</span>
        </div>
        <input type="number" v-model="hq_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用花劵数量"/>

        <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
        <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
        <div class="fl lh100 f26 cr_595757 ml5" style=""> <span class="totals" style="">拥有云宝：</span><span class="cr_fd6847">{{memberInfo.freeze_balance}}</span>
        </div>
        <input type="number" v-model="hm_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用云宝数量"/>

        <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
        <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
        <div class="fl lh100 f26 cr_595757 ml5"> <span class="totals" style="">拥有云通证：</span><span class="cr_fd6847">{{memberInfo.hg_balance}}</span>
        </div>
        <input type="number" v-model="hg_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用云通证数量"/>
        <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
      </ul>

      <ul v-else>
        <li :class="{'on': payType == true}" @click="" class="sli" style="position: relative; height: 2.175rem; line-height: 2.15rem; border-bottom: #dcdddd solid 1px; padding: 0 0rem; overflow: hidden; background: #fff;">
          <!--<div class="LeftIcon fl"><i class="iconfont icon-wechat cr_18aa04"></i></div>-->
          <div class="fl lh100 f26 cr_595757 ml5" style=""> <span class="totals" style="">拥有云宝：</span><span class="cr_fd6847">{{memberInfo.freeze_balance}}</span>
          </div>
          <input type="number" v-model="hm_freeze_balance" class="inp" style="width: 55%;position: absolute;right: 0px" placeholder="请输入使用云宝数量"/>

          <!--<div class="select fr lh100 pr20"><i class="iconfont icon-select"></i></div>-->
        </li>
      </ul>

    </div>
    <div class="BottomGd">
      <span style="margin-left: 10px;line-height: 48px;" class="totals"  v-if="buyInfo.gc_id == 4">需支付:<span class="cr_fd6847">{{payed - hg - hm - hj - hf | toFixed(2)}}</span></span>
      <span style="margin-left: 10px;line-height: 48px;" class="totals" v-else>需支付:<span class="cr_fd6847">￥{{payed - hg - hm - hj - hf | toFixed(2)}}</span></span>
      <button class="but_3 fr bg_45a73a" type="button" @click="switchAddressShow(true)">提交订单</button>
    </div>
    <!--右侧导航Start-->
    <back-nav style="z-index: 100"></back-nav>
    <!--右侧导航End-->

    <!--弹窗-->
    <div v-if="addressShow">
      <div class="PopBg" @click="switchAddressShow(false)" style="z-index: 101"></div>
      <!--选择商品属性弹窗Start-->
      <div class="AttributeSelectionPop " id="AttributeSelectionPop" style="z-index: 101; height: 50%;overflow: scroll; margin-bottom: 2rem">
        <div class="BasicInfo" style="height: 2rem;padding: 0 0 0 0;text-align: center"><i class="iconfont icon-close" @click="switchAddressShow(false)"></i>
          <span style="position: relative;top: 0.6rem;color: #e67a7e;font-size: 16px;">选择收货地址,点击确认订单支付</span>
        </div>
        <div class="detail f24" v-for="(item, index) in addressList.data">
          <div @click="addressSelect(item.address_id)">
            <div class="clear p20 f24 cr_4e4e4e">
              <span class="slhblock slh">{{item.true_name}}</span><span class="fr">{{item.mob_phone}}</span>
            </div>
            <div class=" slh2  hidden pl20 pr20">
              {{item.area_info}} {{item.address}}
            </div>
          </div>

          <div class="detail_sel f-cb p20 cr_999">
            <div v-show="address.address_id == item.address_id" class="fl select_b cr_f95d47">
              <i class="iconfont icon-pitchon2 "></i>
              <span class="pl5">选中</span>
            </div>
            <div v-show="address.address_id != item.address_id" class="fl select_b" @click="addressSelect(item.address_id)">
              <i class="iconfont icon-pitch2"></i>
              <span class="pl5">未选</span>
            </div>
            <div class="fr detail_icon">
            <span @click="editAddress(item.address_id)">
              <i class="iconfont icon-edit2"></i>
              <span class="pr30 pl5">编辑</span>
            </span>
              <span class="delete" @click="delAddress(item.address_id, index)">
              <i class="iconfont icon-del2 pr5"></i>
              <span>删除</span>
            </span>
            </div>
          </div>
        </div>
        <div class="BottomGd">
          <router-link :to="{name: 'address-add', query: {cart: this.$route.query.cart}}" style="float: left; width: 49.5%">
            <span class="but_2 wauto disb tc">+添加新地址</span>
          </router-link>
          <div style="float: left; width: 49.5%;margin-left: 1%" @click="submitOrder">
            <span class="but_2 wauto disb tc">确认订单</span>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import {MessageBox} from 'mint-ui'
  import {mapModules, mapRules} from 'vuet'
  import payPop from '../../components/payPop'

  export default{
    mixins: [
      mapModules({addressList: 'addressList', shopAddressList: 'shopAddressList', memberInfo: 'memberInfo'}),
      mapRules({need: ['addressList', 'shopAddressList', 'memberInfo']})
    ],
    data() {
      return {
        addressShow: false,
        type: this.$route.query.type || 0, // 0 邮寄 1 自提
        from: '',
//        needGoods: this.$storage.getNeedGoods() || false, // 是否需要寄货(刷手才有此选项)
        buyInfo: {total: 0, integral: 0, balance: 0, gc_id: 0, alldata: []},
        useIntegral: false,
        useBalance: false,
        remark: '', // 备注
        order: {order_id: '', pay_sn: ''}, // 提交成功后，对其赋值
        selectedCartIdList: [], // 要购买的商品的cartId列表
        payType: false,
        use_hm: 0,
        hm_freeze_balance: '',
        hg_freeze_balance: '',
        hq_freeze_balance: '',
        hf_freeze_balance: '',
        hg: 0,
        hm: 0,
        hj: 0,
        hf: 0,
        hostName: 'http://' + window.location.hostname
      }
    },
    computed: {
      needGoods: function () {
        return this.memberInfo.is_brush_man != '1'
      },
      integralGet: function () {
        return parseFloat(this.buyInfo.total) + parseFloat(this.buyInfo.total * this.memberInfo.a_rate)
      },
      // 抵扣的余额
      balanceUsed () {
        let balanceMony = parseFloat(parseFloat(this.buyInfo.balance).toFixed(2))
        let totalMony = parseFloat(parseFloat(this.buyInfo.total).toFixed(2))
        let remain = totalMony
        if (this.useIntegral) {
          remain = parseFloat((totalMony - this.integralUsed).toFixed(2))
        }
        return balanceMony > remain ? remain : balanceMony
      },
      // 抵扣的积分金额
      integralUsed () {
        let integralMoney = parseInt(this.buyInfo.integral) // 1积分1元
        let halfTotalMoney = parseInt((parseFloat(this.buyInfo.total) / 2).toFixed(2)) // 最多可使用订单总额的50%
        return integralMoney > halfTotalMoney ? halfTotalMoney : integralMoney
      },
      // 抵扣后需支付的金额
      payed () {
        let remain = parseFloat(this.buyInfo.total)
        if (this.useIntegral) {
          remain = remain - this.integralUsed
        }
        if (this.useBalance) {
          remain = remain - this.balanceUsed
        }
        return remain
      },
      address () {
        if (this.$route.query.addressId) {
          for (let i = 0; i < this.addressList.data.length; i++) {
            if (this.addressList.data[i].address_id == this.$route.query.addressId) {
              return this.addressList.data[i] // 使用指定地址
            }
          }
        } else {
          for (let i = 0; i < this.addressList.data.length; i++) {
            if (this.addressList.data[i].is_default === '1') {
              // return this.addressList.data[i] // 使用默认地址
            }
          }
          if (this.addressList.data.length > 0) {
            return this.addressList.data[0] // 没有默认地址，使用第一个地址
          }
        }
        return {} // 没有地址
      },
      shopAddress () {
        if (this.$route.query.shopAddressId) {
          for (let i = 0; i < this.shopAddressList.data.length; i++) {
            if (this.shopAddressList.data[i].address_id == this.$route.query.shopAddressId) {
              return this.shopAddressList.data[i] // 使用指定地址
            }
          }
        } else {
          for (let i = 0; i < this.shopAddressList.data.length; i++) {
            if (this.shopAddressList.data[i].is_default === '1') {
              return this.shopAddressList.data[i] // 使用默认地址
            }
          }
          if (this.shopAddressList.data.length > 0) {
            return this.shopAddressList.data[0] // 没有默认地址，使用第一个地址
          }
        }
        return {} // 没有地址
      }
    },
    components: {},
    created() {
//      if (this.from === 'address-list' || this.from === 'address-add') {  // 选择地址页跳回
//        return
//      }
//       this.$request.getAddressList().then(data => {
//       })
      console.log('query', this.$route.query.cart)
      this.selectedCartIdList = this.$route.query.cart.toString().split(',')
      console.log('cartIdList', this.$route.query, this.selectedCartIdList)
      this.getBuyInfo(this.selectedCartIdList)
    },
    watch: {
      $route () {
        this.type = this.$route.query.type
      },
      hf_freeze_balance: function () {
        if (parseFloat(this.hf_freeze_balance) < 0) {
          this.hf_freeze_balance = 0
        }
        // this.$toast(this.hm_freeze_balance)
        if (parseFloat(this.hf_freeze_balance) > parseFloat(this.buyInfo.total) || parseFloat(this.hf_freeze_balance) > parseFloat(this.memberInfo.hf_balance)) {
          if (parseFloat(this.memberInfo.hf_balance) < parseFloat(this.buyInfo.total) * 1.0) {
            this.hf_freeze_balance = (this.memberInfo.hf_balance * 1.0).toFixed(2) - this.hg
            this.$toast('云宝超过最大值,限制额度')
          } else {
            this.hf_freeze_balance = parseFloat(this.buyInfo.total - this.hg).toFixed(2)
          }
        }
        if (this.buyInfo.gc_id == '4') {
          if (parseFloat(this.memberInfo.hf_balance) > this.buyInfo.g_hf_price) {
            this.hf_freeze_balance = this.buyInfo.g_hf_price
          } else {
            this.hf_freeze_balance = this.memberInfo.hf_balance
            this.$toast('需要支付的价格超过您拥有的云积分')
          }
        }
        // if ((parseFloat(this.hm_freeze_balance) + parseFloat(this.hg_freeze_balance)) > this.buyInfo.total) {
        //   this.hm_freeze_balance = (parseFloat(this.hm_freeze_balance) - parseFloat(this.hg_freeze_balance)).toFixed(2)
        //   this.$toast(parseFloat(this.hm_freeze_balance + this.hg_freeze_balance).toString())
        // }
        this.hf = this.hf_freeze_balance.toString()
      },
      hm_freeze_balance: function () {
        if (parseFloat(this.hm_freeze_balance) < 0) {
          this.hm_freeze_balance = 0
        }
        // this.$toast(this.hm_freeze_balance)
        if (parseFloat(this.hm_freeze_balance) > parseFloat(this.buyInfo.total) || parseFloat(this.hm_freeze_balance) > parseFloat(this.memberInfo.freeze_balance)) {
          if (parseFloat(this.memberInfo.freeze_balance) < parseFloat(this.buyInfo.total) * 1.0) {
            this.hm_freeze_balance = (this.memberInfo.freeze_balance * 1.0).toFixed(2) - this.hg
            this.$toast('云宝超过最大值,限制额度')
          } else {
            this.hm_freeze_balance = parseFloat(this.buyInfo.total - this.hg).toFixed(2)
          }
        }
        if (this.buyInfo.gc_id == '4') {
          if (parseFloat(this.memberInfo.freeze_balance) > this.buyInfo.g_hm_price) {
            this.hm_freeze_balance = this.buyInfo.g_hm_price
          } else {
            this.hm_freeze_balance = this.memberInfo.freeze_balance
            this.$toast('需要支付的价格超过您拥有的云积分')
          }
        }
        // if ((parseFloat(this.hm_freeze_balance) + parseFloat(this.hg_freeze_balance)) > this.buyInfo.total) {
        //   this.hm_freeze_balance = (parseFloat(this.hm_freeze_balance) - parseFloat(this.hg_freeze_balance)).toFixed(2)
        //   this.$toast(parseFloat(this.hm_freeze_balance + this.hg_freeze_balance).toString())
        // }
        this.hm = this.hm_freeze_balance.toString()
      },
      hg_freeze_balance: function () {
        if (parseFloat(this.hg_freeze_balance) < 0) {
          this.hg_freeze_balance = 0
        }
        if (parseFloat(this.buyInfo.total) == this.hm_freeze_balance) {
          this.hg_freeze_balance = 0
          return
        }
        if (parseFloat(this.hg_freeze_balance) > parseFloat(this.buyInfo.total)) {
          if (parseFloat(this.memberInfo.hg_balance) < parseFloat(this.buyInfo.total)) {
            this.hg_freeze_balance = this.memberInfo.hg_balance
            this.$toast('云通证超过最大值,限制额度')
          } else {
            this.hg_freeze_balance = this.buyInfo.total
            // this.$toast('花股超过购买最大值,限制额度')
          }
        }
        if (this.buyInfo.gc_id == '4') {
          if (parseFloat(this.memberInfo.hg_balance) > this.buyInfo.g_hg_price) {
            this.hg_freeze_balance = this.buyInfo.g_hg_price
          } else {
            this.hg_freeze_balance = this.memberInfo.hg_balance
            this.$toast('需要支付的价格超过您拥有的云积分')
          }
        }

        this.hg = this.hg_freeze_balance.toString()
      },
      hq_freeze_balance: function () {
        if (parseFloat(this.hq_freeze_balance) < 0) {
          this.hq_freeze_balance = 0
        }
        if (parseFloat(this.hq_freeze_balance) > parseFloat(this.buyInfo.total)) {
          if (parseFloat(this.memberInfo.hq_balance) < parseFloat(this.buyInfo.total)) {
            this.hq_freeze_balance = this.memberInfo.hq_balance
            this.$toast('云劵超过最大值,限制额度')
          } else {
            this.hq_freeze_balance = this.buyInfo.total
            this.$toast('云劵超过购买最大值,限制额度')
          }
        }
        // if (parseFloat(this.hq_freeze_balance) < parseFloat(this.buyInfo.total) * 0.2) {
        //   this.hq_freeze_balance = parseFloat(this.buyInfo.total) * 0.2
        //   this.$toast('花劵支付不得低于商品价格的20%')
        // }
        this.hj = this.hq_freeze_balance.toString()
      }
    },
    methods: {
      addressSelect(id) {
        // console.log(this.type.toString())
        this.$router.replace({name: 'order-confirm', query: {cart: this.$route.query.cart, type: this.type, addressId: id}})
        // this.$route.query.addressId = id
      },
      switchAddressShow(sign) {
        this.addressShow = sign
      },
      switchPayType() {
        this.payType = !this.payType
        if (this.payType == true) {
          this.use_hm = 1
        } else {
          this.use_hm = 0
        }
        // this.$toast(this.use_hm)
      },
      switchNeedGoods(boolValue) {
        this.needGoods = boolValue
//        this.$storage.setNeedGoods(boolValue)
      },
      switchType(value) {
        this.$router.replace({name: 'order-confirm', query: {cart: this.$route.query.cart, type: value}})
      },
      switchUseBalance(boolValue) {
        this.useBalance = boolValue
      },
      switchIntegral(boolValue) {
        if (this.integralUsed < 0 && !boolValue) { // 积分为负数时，不让用户取消勾选，必须要多付款，抹平积分。
          return
        }
        this.useIntegral = boolValue
      },
      gotoAddAddress() {
        this.$router.push({
          name: 'address-add',
          query: {from: 'order-confirm', cart: this.$route.query.cart, type: this.type}
        })
      },
      getBuyInfo(idList) {
        this.$request.getBuyInfo(idList).then(data => {
          this.buyInfo = data
          this.hq_freeze_balance = parseFloat(this.buyInfo.total) * 0.2
          if (this.buyInfo.gc_id == '4') {
            this.hf_freeze_balance = this.buyInfo.g_hf_price
            this.hg_freeze_balance = this.buyInfo.g_hg_price
            this.hm_freeze_balance = this.buyInfo.g_hm_price
          }
        })
      },
      selectAddress() {
        this.$router.push({
          name: 'address-list',
          query: {from: 'order-confirm', cart: this.$route.query.cart, type: this.type}
        })
      },
      selectShopAddress() {
        this.$router.push({
          name: 'address-shop',
          query: {from: 'order-confirm', cart: this.$route.query.cart, type: this.type}
        })
      },
      submitOrder() {
        let param = {
          cart_id: this.selectedCartIdList,
          ifcart: 1,
          is_balance: this.useBalance ? 1 : 0,
          is_integral: this.useIntegral ? 1 : 0,
          order_note: this.remark,
          pay_name: 'online',
          self: this.type,
          is_needship: this.needGoods ? 1 : 0,
          use_hm: this.use_hm,
          address_id: 0,
          hm_pay: 0,
          hg_pay: 0,
          hq_pay: 0,
          order_type: 0
        }
        if (this.buyInfo.gc_id == '3') {
          param.order_type = 0
          if (parseFloat(this.hq_freeze_balance) < parseFloat(this.buyInfo.total) * 0.2) {
            this.$toast('云劵支付必须不小于商品价格的20%')
            this.hq_freeze_balance = parseFloat(this.buyInfo.total) * 0.2
            return
          }
        } else if (this.buyInfo.gc_id == '4') {
          param.order_type = 2
          if (parseFloat(this.hg_freeze_balance) != this.buyInfo.g_hg_price) {
            this.$toast('您的云通证与云积分数量不足以购买此商品')
            return
          }
          if (parseFloat(this.hf_freeze_balance) != this.buyInfo.g_hf_price) {
            this.$toast('您的云通证与云积分数量不足以购买此商品')
            return
          }
          if (parseFloat(this.hm_freeze_balance) != this.buyInfo.g_hm_price) {
            this.$toast('您的云通证与云积分数量不足以购买此商品')
            return
          }
        } else {
          param.order_type = 1
        }

        console.log(this.hg)
        console.log(this.hm)
        console.log(this.hj)
        if (this.hg == '') {
          this.hg = 0
        }
        if (this.hm == '') {
          this.hm = 0
        }
        if (this.hj == '') {
          this.hj = 0
        }
        if (this.buyInfo.total < (parseFloat(this.hg) + parseFloat(this.hm) + parseFloat(this.hj))) {
          this.$toast('积分支付数量超过金额总数，请重新输入')
          return
        }
        // this.$toast('4445')
        // this.$toast(this.payed.to)
        if (this.type == 0) { // 邮寄
          param.address_id = this.address.address_id
        } else if (this.type == 1) { // 自提
          param.address_id = this.shopAddress.address_id
        }
        if (!param.address_id) {
          this.$toast('请先选择地址')
          return
          // param.address_id = 0
        }
        if (this.hm_freeze_balance != '') {
          param.hm_pay = this.hm_freeze_balance
        }
        if (this.hg_freeze_balance != '') {
          param.hg_pay = this.hg_freeze_balance
        }
        if (this.hq_freeze_balance != '') {
          param.hq_pay = this.hq_freeze_balance
        }
        if (this.hf_freeze_balance != '') {
          param.hf_pay = this.hf_freeze_balance
          console.log('sdsfsed:' + this.hf_freeze_balance)
          // if (parseFloat(this.hf_freeze_balance) < parseFloat(this.buyInfo.total)) {
          //   this.$toast('输入的花粉数额不足')
          //   return
          // } else if (parseFloat(this.hf_freeze_balance) > parseFloat(this.buyInfo.total)) {
          //   this.$toast('输入的花粉数额超过价格')
          //   return
          // }
        }
        if (this.buyInfo.gc_id == '4' && (parseFloat(this.hm_freeze_balance) + parseFloat(this.hf_freeze_balance) + parseFloat(this.hg_freeze_balance)) - this.payed != 0) {
          this.$toast('需支付的价钱存在偏差，请联系管理员')
          return
        }
        this.$request.submitOrder(param).then(data => {
//          this.$toast('提交订单成功')
          this.selectedCartIdList = []
          this.order = data
          if (parseFloat(parseFloat(this.payed).toFixed(2)) - 0 <= 0) { // 通过帐号余额支付，不需要走第三方支付
            this.$router.replace({name: 'order-success', query: {id: this.order.order_id}})
            return
          }
          let paySn = this.order.pay_sn
          if (data.is_pay == 1) {
            this.$router.replace({name: 'order-list'})
          } else {
            payPop({paySn: paySn, orderId: this.order.order_id}, this.canclePay)
          }
        }).catch(e => {
          this.$toast('订单提交失败:' + e.msg)
        })
      },
      canclePay() {
        this.$router.replace({name: 'order-detail', params: {id: this.order.order_id}})
      },
      editAddress(id) {
        this.$router.push({name: 'address-edit', params: {id: id}})
      },
      delAddress(id, index) {
        MessageBox.confirm(`你确定要删除吗?`).then(action => {
          this.$request.delAddress(id).then(data => {
            this.addressList.data.splice(index, 1)
            this.$toast('删除成功')
          }).catch(e => {
            console.error('删除地址失败', e)
            this.$toast('删除失败:' + e.msg)
          })
        }).catch(() => {
        })
      }
    }
  }
</script>

<style>
  .pwd-wrap {
    width: 100%;
    height: 40px;
    padding-bottom: 1px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #ddd;
    display: flex;
    display: -webkit-box;
    display: -webkit-flex;
    cursor: pointer;
    position: absolute;
    top: 0;
  }

  .pwd-wrap li {
    list-style-type: none;
    text-align: center;
    line-height: 44px;
    -webkit-box-flex: 1;
    flex: 1;
    -webkit-flex: 1;
    border-right: 1px solid #ddd;
  }

  .pwd-wrap li:last-child {
    border-right: 0;
  }

  .pwd-wrap li i {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    background: #000;
    display: inline-block;
  }
</style>
